﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.XCMG.Util;

namespace PMS.XCMG.Entity
{
    /// <summary>
    /// 菜单
    /// </summary>
    public partial class Sys_Menu : BusEntity, ITreeModel<Sys_Menu>
    {
        /// <summary>
        /// 上级菜单
        /// </summary>
        public string ParentId { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 编码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 图标
        /// </summary>
        public string Icon { get; set; }
        /// <summary>
        /// 路径
        /// </summary>
        public string Path { get; set; }
        /// <summary>
        /// 组件
        /// </summary>
        public string Component { get; set; }
        /// <summary>
        /// 跳转
        /// </summary>
        public string Redirect { get; set; }
        /// <summary>
        /// 排序
        /// </summary>
        public int Seq { get; set; }
    }

    public partial class Sys_Menu : BusEntity
    {
        /// <summary>
        /// 上级菜单
        /// </summary>
        public Sys_Menu Parent { get; set; }
        /// <summary>
        /// 下级菜单
        /// </summary>
        public List<Sys_Menu> Children { get; set; }

        /// <summary>
        /// 操作
        /// </summary>
        public List<Sys_Action> Actions { get; set; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class Sys_MenuTypeConfig : BusEntityTypeConfig<Sys_Menu>, IEntityTypeConfiguration<Sys_Menu>
    {
        public override void Configure(EntityTypeBuilder<Sys_Menu> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.Parent).WithMany(p => p.Children).HasForeignKey(p => p.ParentId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.ParentId).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefMiddleColLen).IsRequired();
            builder.Property(p => p.Code).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Icon).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.Path).HasMaxLength(EntityDefinition.DefMiddleColLen);
            builder.Property(p => p.Component).HasMaxLength(EntityDefinition.DefMiddleColLen);
            builder.Property(p => p.Redirect).HasMaxLength(EntityDefinition.DefMiddleColLen);
            builder.Property(p => p.Seq).IsRequired().HasDefaultValue(0);
            #endregion

            #region 备注
            builder.HasComment("菜单");
            builder.Property(p => p.ParentId).HasComment("上级菜单");
            builder.Property(p => p.Name).HasComment("名称");
            builder.Property(p => p.Code).HasComment("编码");
            builder.Property(p => p.Icon).HasComment("图标");
            builder.Property(p => p.Path).HasComment("路径");
            builder.Property(p => p.Component).HasComment("组件");
            builder.Property(p => p.Redirect).HasComment("跳转");
            builder.Property(p => p.Seq).HasComment("排序");
            #endregion

            #region 种子数据

            #region 生产调度
            builder.HasData(new Sys_Menu() { Id = "400", ParentId = null, Name = "生产调度", Code = "Exec", Icon = "control", Path = "/Exec", Component = "RouteView", Redirect = "/Exec/Plan", Seq = 4, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "401", ParentId = "400", Name = "生产计划", Code = "Plan", Icon = "reconciliation", Path = "/Exec/Plan", Component = "/Exec/Plan/List", Redirect = null, Seq = 1, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "402", ParentId = "400", Name = "来料预收", Code = "Precollected", Icon = "reconciliation", Path = "/Exec/Precollected", Component = "/Exec/Precollected/List", Redirect = null, Seq = 2, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "403", ParentId = "400", Name = "实收记录", Code = "RealIncome", Icon = "reconciliation", Path = "/Exec/RealIncome", Component = "/Exec/RealIncome/List", Redirect = null, Seq = 3, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "404", ParentId = "400", Name = "生产报工", Code = "StationExecuted", Icon = "reconciliation", Path = "/Exec/StationExecuted", Component = "/Exec/StationExecuted/List", Redirect = null, Seq = 4, CreateUserId = "1", ModifyUserId = "1" });
            #endregion

            #region 生产工艺
            builder.HasData(new Sys_Menu() { Id = "500", ParentId = null, Name = "生产工艺", Code = "Craft", Icon = "bg-colors", Path = "/Craft", Component = "RouteView", Redirect = "/Define/CraftStep", Seq = 5, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "501", ParentId = "500", Name = "流程步骤", Code = "CraftStep", Icon = "api", Path = "/Define/CraftStep", Component = "/Define/CraftStep/List", Redirect = null, Seq = 1, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "502", ParentId = "500", Name = "加工工序", Code = "CraftStepProcess", Icon = "ordered-list", Path = "/Define/CraftStepProcess", Component = "/Define/CraftStepProcess/List", Redirect = null, Seq = 2, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "503", ParentId = "500", Name = "下发配置", Code = "SpecAssign", Icon = "ordered-list", Path = "/Define/SpecAssign", Component = "/Define/SpecAssign/List", Redirect = null, Seq = 3, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "504", ParentId = "500", Name = "下发数据", Code = "PlcAssign", Icon = "ordered-list", Path = "/Define/PlcAssign", Component = "/Define/PlcAssign/List", Redirect = null, Seq = 4, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "506", ParentId = "500", Name = "叶片分拣", Code = "MaterielSorting", Icon = "robot", Path = "/Define/MaterielSortingConfig", Component = "/Define/MaterielSortingConfig/List", Redirect = null, Seq = 7, CreateUserId = "1", ModifyUserId = "1" });
            #endregion

            #region 产线配置
            builder.HasData(new Sys_Menu() { Id = "600", ParentId = null, Name = "产线配置", Code = "WorkshoManager", Icon = "cluster", Path = "/Worksho", Component = "RouteView", Redirect = "/Define/Team", Seq = 6, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "601", ParentId = "600", Name = "生产车间", Code = "Worksho", Icon = "bank", Path = "/Define/Worksho", Component = "/Define/Worksho/List", Redirect = null, Seq = 1, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "602", ParentId = "600", Name = "生产区域", Code = "WorkshoArea", Icon = "select", Path = "/Define/WorkshoArea", Component = "/Define/WorkshoArea/List", Redirect = null, Seq = 2, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "603", ParentId = "600", Name = "生产单元", Code = "WorkshoUnit", Icon = "interaction", Path = "/Define/WorkshoUnit", Component = "/Define/WorkshoUnit/List", Redirect = null, Seq = 3, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "604", ParentId = "600", Name = "生产工位", Code = "WorkshoStation", Icon = "idcard", Path = "/Define/WorkshoStation", Component = "/Define/WorkshoStation/List", Redirect = null, Seq = 4, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "605", ParentId = "600", Name = "设备台帐", Code = "Equipment", Icon = "robot", Path = "/Define/Equipment", Component = "/Define/Equipment/List", Redirect = null, Seq = 5, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "606", ParentId = "600", Name = "缓存区域", Code = "Storage", Icon = "robot", Path = "/Define/StorageArea", Component = "/Define/StorageArea/List", Redirect = null, Seq = 6, CreateUserId = "1", ModifyUserId = "1" });
            
            #endregion

            #region 班组管理
            builder.HasData(new Sys_Menu() { Id = "700", ParentId = null, Name = "班组管理", Code = "TeamManager", Icon = "apartment", Path = "/Team", Component = "RouteView", Redirect = "/Define/Team", Seq = 7, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "701", ParentId = "700", Name = "班时管理", Code = "TeamTime", Icon = "clock-circle", Path = "/Define/TeamTime", Component = "/Define/TeamTime/List", Redirect = null, Seq = 1, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "702", ParentId = "700", Name = "班组管理", Code = "Team", Icon = "deployment-unit", Path = "/Define/Team", Component = "/Define/Team/List", Redirect = null, Seq = 2, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "703", ParentId = "700", Name = "成员管理", Code = "TeamMember", Icon = "team", Path = "/Define/TeamMember", Component = "/Define/TeamMember/List", Redirect = null, Seq = 3, CreateUserId = "1", ModifyUserId = "1" });
            #endregion

            #region 物料管理
            builder.HasData(new Sys_Menu() { Id = "800", ParentId = null, Name = "物料管理", Code = "Material", Icon = "qrcode", Path = "/Define", Component = "RouteView", Redirect = "/Define/MaterielInfor", Seq = 8, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "801", ParentId = "800", Name = "物料类型", Code = "MaterielType", Icon = "tag", Path = "/Define/MaterielType", Component = "/Define/MaterielType/List", Redirect = null, Seq = 1, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "802", ParentId = "800", Name = "物料信息", Code = "MaterielInfor", Icon = "profile", Path = "/Define/MaterielInfor", Component = "/Define/MaterielInfor/List", Redirect = null, Seq = 2, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "803", ParentId = "800", Name = "BOM管理", Code = "MaterialBom", Icon = "branches", Path = "/Define/MaterialBom", Component = "/Define/MaterialBom/List", Redirect = null, Seq = 3, CreateUserId = "1", ModifyUserId = "1" });
            #endregion

            #region 系统管理
            builder.HasData(new Sys_Menu() { Id = "900", ParentId = null, Name = "系统管理", Code = "Sys", Icon = "setting", Path = "/Sys", Component = "RouteView", Redirect = "/Sys/Sys_Org", Seq = 9, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "901", ParentId = "900", Name = "组织架构", Code = "Sys_Org", Icon = "cluster", Path = "/Sys/Sys_Org", Component = "/Sys/Sys_Org/List", Redirect = null, Seq = 1, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "902", ParentId = "900", Name = "用户管理", Code = "Sys_User", Icon = "user", Path = "/Sys/Sys_User", Component = "/Sys/Sys_User/List", Redirect = null, Seq = 2, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "903", ParentId = "900", Name = "角色管理", Code = "Sys_Role", Icon = "team", Path = "/Sys/Sys_Role", Component = "/Sys/Sys_Role/List", Redirect = null, Seq = 3, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "904", ParentId = "900", Name = "菜单管理", Code = "Sys_Menu", Icon = "menu", Path = "/Sys/Sys_Menu", Component = "/Sys/Sys_Menu/List", Redirect = null, Seq = 4, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "905", ParentId = "900", Name = "数据字典", Code = "CF_Enum", Icon = "key", Path = "/Sys/CF_Enum", Component = "/CF/CF_Enum/List", Redirect = null, Seq = 5, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "906", ParentId = "900", Name = "系统参数", Code = "CF_Config", Icon = "code", Path = "/Sys/CF_Config", Component = "/CF/CF_Config/List", Redirect = null, Seq = 6, CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new Sys_Menu() { Id = "907", ParentId = "900", Name = "编码规则", Code = "CF_CodeType", Icon = "number", Path = "/Sys/CF_CodeType", Component = "/CF/CF_CodeType/List", Redirect = null, Seq = 7, CreateUserId = "1", ModifyUserId = "1" });
            #endregion

            #endregion
        }
    }
}

